package com.hxh.area.controller;

import com.hxh.area.service.AreaService;
import com.hxh.area.vo.ResultVo;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author huangxunhui
 * Date: Created in 2021/8/14 23:03
 * Utils: IntelliJ IDEA
 */
@RestController
@AllArgsConstructor
@RequestMapping("/area")
public class AreaController {

    private final AreaService areaService;

    @GetMapping("/parse")
    public void parase() throws IOException {
        areaService.parase();
    }

    @GetMapping("/list")
    public ResultVo listProvince() {
        return ResultVo.success(areaService.list(0));
    }

    @GetMapping("/list/{parent}")
    public ResultVo list(@PathVariable(value = "parent") Integer parent) {
        return ResultVo.success(areaService.list(parent));
    }

}
